//ST*****************************************文本框*****************************************
function RxText() {
}
RxText.init = function(id, value, emptyText, style, callback, isLabel) {
    var ctrl = document.getElementById(id);
	if (!ctrl) {
		ctrl = document.createElement("div");
	}

    ctrl.dispose = RxCommon.dispose;
    ctrl.dispose();

	if (id) {
		ctrl.id = id;
	}
    ctrl.rxtype = "RxText";
    ctrl.className = "rxtext";
    ctrl.value = RxCommon.toDefault(value,"");
    ctrl.emptyText = RxCommon.toDefault(emptyText,"");
    ctrl.isLabel =  RxCommon.toDefault(isLabel,false);

    if (style) {
    	RxCommon.setStyle(ctrl, style);
    }

    ctrl.ce = RxCommon.ce;

	ctrl.callback = callback;
    ctrl.input = ctrl.ce(ctrl, null, "input", "rxtext_input");
    ctrl.input.type = "text";
    ctrl.input.value = value;
    ctrl.tips = ctrl.ce(ctrl, null, "div", "rxtext_tip");
    ctrl.tips.innerHTML = emptyText;

	ctrl.setReadOnly = function(isReadOnly) {
		if (isReadOnly) {
			this.input.setAttribute("readonly", true);
		} else {
			this.input.removeAttribute("readonly");
		}
		this.refresh();
	};

	ctrl.input.onfocus = function() {
		this._self.input.focus();
		this._self.tips.style.display = "none";
		this._self.className = "rxtext_focus";
		if (this._self.isLabel === true) {
			this._self.style.border = "0px";
		}
	};

	ctrl.tips.onclick = function() {
		this._self.input.focus();
		this._self.tips.style.display = "none";
		this._self.className = "rxtext_focus";
		if (this._self.isLabel === true) {
			this._self.style.border = "0px";
		}
	};

	ctrl.input.onblur = function() {
		this._self.refresh();
	};

	ctrl.input.onkeyup = function(e) {
		if (this._self.callback) {
			var rxevent = {};
			rxevent.e = e;
			rxevent.name = "onkeydown";
			rxevent.self = this._self._self;
			rxevent.target = this;
			rxevent.source = this._self;
			rxevent.value = this.value;
			this._self.callback(rxevent);
		}
		return true;
	};
	ctrl.input.onchange = function(e) {
		if (this._self.callback) {
			var rxevent = {};
			rxevent.name = "onchange";
			rxevent.self = this._self._self;
			rxevent.target = this;
			rxevent.source = this._self;
			rxevent.value = this.value;
			this._self.callback(rxevent);
		}
		return true;
	};

	ctrl.refresh = function() {
		if (this.input.getAttribute("readonly") === undefined || this.input.getAttribute("readonly") === null) {
			if (RxCommon.isEmpty(this.input.value)) {
				this.tips.style.display = "block";
			} else {
				this.tips.style.display = "none";
			}
		} else {
			this.tips.style.display = "none";
		}
		this.className = "rxtext";
		if (this.isLabel === true) {
			this.style.border = "0px";
		}
	};

	ctrl.getValue = function() {
		return this.input.value;
	};

	ctrl.setValue = function(value) {
		this.input.value = value;
		this.refresh();
	};

	ctrl.resize = function() {
		var width = 100 - (5*100/$(this).width());
		this.input.style.width = width + "%";
		this.tips.style.width = width + "%";
		this.input.style.height = ($(this).height()-4) + "px";
		this.tips.style.height = ($(this).height()-4) + "px";
		this.input.style.lineHeight = ($(this).height()-4) + "px";
		this.tips.style.lineHeight = ($(this).height()-4) + "px";
	};

	ctrl.refresh();
	ctrl.resize();

    return ctrl;
}
//ED*****************************************文本框*****************************************
